﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CubePuzzle
{

    class IO
    {
        private String path;
        private TextReader input;

        private int numberOfItems;
        private int dim;
       
        public IO(int index) {
            path = "input\\" + index.ToString()+"\\";
            input = new StreamReader(path + "0.txt");
            numberOfItems = Convert.ToInt32(input.ReadLine());
            Random random = new Random();
            int foldername = random.Next(numberOfItems);
            input.Close();
            path += foldername.ToString() + "\\";
            input = new StreamReader(path + "0.txt");
            numberOfItems = Convert.ToInt32(input.ReadLine());
            input.Close();
        }

        public int getDim() 
        {
            return dim;
        }

        public int getNumberOfItems()
        {
            return numberOfItems;
        }

        public Item[] getItems()
        {
            Item [] temp = new Item[numberOfItems];
            for (int ii = 0; ii < numberOfItems; ii++)
            {
                input = new StreamReader(path + "g" + (ii+1).ToString() + ".txt");
                dim = Convert.ToInt32(input.ReadLine());
                temp[ii] = new Item(dim);
                input.ReadLine();
                for (int ix = 0; ix < dim; ix++)
                {
                    for (int jx = 0; jx < dim; jx++)
                    {
                        String inputLine = input.ReadLine();
                        for (int k = 0; k < dim; k++)
                        {
                            char c = inputLine[2*k];
                            temp[ii].setItem(jx, k, ix, Convert.ToInt32(new String(c,1))*(ii+1));
                        }
                    }
                    input.ReadLine();
                }
                input.Close();
            }

            return temp;
        }

    }
}
